﻿using CGT.OP.Common;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            List<WxSubMenuButton> l = new List<WxSubMenuButton>();
            List<WxMenuButton> s = new List<WxMenuButton>();
            WxSubMenuButton sub = new WxSubMenuButton();
            sub.name = "搜索";
            sub.type = "view";
            sub.url = "http://www.aa.com";
            l.Add(sub);
            sub = new WxSubMenuButton();
            sub.name = "搜索1";
            sub.type = "view1";
            sub.url = "http://www.bb.com";
            sub.appid = null;
            l.Add(sub);
            WxMenuButton w = new WxMenuButton();
            w.name = "菜单";
            w.type = "view";
            w.url = "http://www.aa.com";
            w.sub_button = l;
            s.Add(w);
            w = new WxMenuButton();
            w.name = "菜单1";
            w.type = "view1";
            w.url = "http://www.bb.com";
            s.Add(w);
            WxMenuModel model = new WxMenuModel();
            model.button = s;
            var jsonSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore };
            var json = JsonConvert.SerializeObject(model, Formatting.Indented, jsonSetting);

            string aa = Newtonsoft.Json.JsonConvert.SerializeObject(model);
            string f = "";
        }

        private void button2_Click(object sender, EventArgs e)
        {
            WxHelper wx = new WxHelper();
            this.textBox1.Text =  wx.GetMenu();
            
        }
    }

    public class WxMenuModel
    {
        public List<WxMenuButton> button
        {
            get; set;
        }
    }

    public class WxMenuButton
    {
        public string type
        {
            get; set;
        }

        public string name
        {
            get; set;
        }

        public string url
        {
            get; set;
        }

        public List<WxSubMenuButton> sub_button
        {
            get; set;
        }

        public string appid
        {
            get; set;
        }

        public string pagepath
        {
            get; set;
        }

    }

    public class WxSubMenuButton
    {
        public string type
        {
            get; set;
        }

        public string name
        {
            get; set;
        }

        public string url
        {
            get; set;
        }

        public string appid
        {
            get; set;
        }

        public string pagepath
        {
            get; set;
        }
    }
}
